﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WJP.Utils;

namespace WJP.ComponentModel
{
    /// <summary>
    /// 从文件夹加载插件
    /// </summary>
    public class FolderPluginSource : PluginSourceBase
    {
        public string Folder { get; }

        public SearchOption SearchOption { get; set; }

        /// <summary>
        /// 加载文件夹的插件，默认不搜索子文件夹
        /// </summary>
        /// <param name="folder">文件夹路径</param>
        /// <param name="searchOption">搜索类型，默认不搜索子文件夹</param>
        public FolderPluginSource(string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            Folder = folder;
            SearchOption = searchOption;
        }

        /// <summary>
        /// 从指定的文件夹加载程序集
        /// </summary>
        /// <returns></returns>
        protected override List<Assembly> LoadAssemblies()
        {
            return Helper.GetAllAssembliesInFolder(Folder, SearchOption);
        }
    }
}
